﻿using System;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace CodePlex.TeamFoundation.Adapters.WorkItemTracking
{
  /// <summary>
  /// Adapter that implements the IWorkItem interface for 
  /// Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem
  /// </summary>
  public class WorkItemAdapter : IWorkItem
  {
    #region Constructors

    private WorkItemAdapter()
    {
      // Hide the default constuctor
    }

    public WorkItemAdapter(WorkItem sourceWorkItem)
    {
      tfsWorkItem = sourceWorkItem;
      tfsWorkItem.FieldChanged += this.FieldChanged;
    }

    #endregion

    #region Private Variables

    WorkItem tfsWorkItem;

    #endregion

    #region IWorkItem Members

    public event WorkItemFieldChangeEventHandler FieldChanged;

    public int AreaId
    {
      get
      {
        return tfsWorkItem.AreaId;
      }
      set
      {
        tfsWorkItem.AreaId = value;
      }
    }

    public string AreaPath
    {
      get
      {
        return tfsWorkItem.AreaPath;
      }
      set
      {
        tfsWorkItem.AreaPath = value;
      }
    }

    public int AttachedFileCount
    {
      get { return tfsWorkItem.AttachedFileCount; }
    }

    public AttachmentCollection Attachments
    {
      get { return tfsWorkItem.Attachments; }
    }

    public string ChangedBy
    {
      get { return tfsWorkItem.ChangedBy; }
    }

    public DateTime ChangedDate
    {
      get { return tfsWorkItem.ChangedDate; }
    }

    public string CreatedBy
    {
      get { return tfsWorkItem.CreatedBy; }
    }

    public DateTime CreatedDate
    {
      get { return tfsWorkItem.CreatedDate; }
    }

    public string Description
    {
      get
      {
        return tfsWorkItem.Description;
      }
      set
      {
        tfsWorkItem.Description = value;
      }
    }

    public string DisplayForm
    {
      get { return tfsWorkItem.DisplayForm; }
    }

    public int ExternalLinkCount
    {
      get { return tfsWorkItem.ExternalLinkCount; }
    }

    public FieldCollection Fields
    {
      get { return tfsWorkItem.Fields; }
    }

    public string History
    {
      get
      {
        return tfsWorkItem.History;
      }
      set
      {
        tfsWorkItem.History = value;
      }
    }

    public int HyperLinkCount
    {
      get { return tfsWorkItem.HyperLinkCount; }
    }

    public int Id
    {
      get { return tfsWorkItem.Id; }
    }

    public bool IsDirty
    {
      get { return tfsWorkItem.IsDirty; }
    }

    public bool IsOpen
    {
      get { return tfsWorkItem.IsOpen; }
    }

    public bool IsPartialOpen
    {
      get { return tfsWorkItem.IsPartialOpen; }
    }

    public bool IsReadOnlyOpen
    {
      get { return tfsWorkItem.IsReadOnlyOpen; }
    }

    public int IterationId
    {
      get
      {
        return tfsWorkItem.IterationId;
      }
      set
      {
        tfsWorkItem.IterationId = value;
      }
    }

    public string IterationPath
    {
      get
      {
        return tfsWorkItem.IterationPath;
      }
      set
      {
        tfsWorkItem.IterationPath = value;
      }
    }

    public LinkCollection Links
    {
      get { return tfsWorkItem.Links; }
    }

    public string NodeName
    {
      get { return tfsWorkItem.NodeName; }
    }

    public Project Project
    {
      get { return tfsWorkItem.Project; }
    }

    public string Reason
    {
      get
      {
        return tfsWorkItem.Reason ;
      }
      set
      {
        tfsWorkItem.Reason = value;
      }
    }

    public int RelatedLinkCount
    {
      get { return tfsWorkItem.RelatedLinkCount; }
    }

    public int Rev
    {
      get { return tfsWorkItem.Rev; }
    }

    public DateTime RevisedDate
    {
      get { return tfsWorkItem.RevisedDate; }
    }

    public int Revision
    {
      get { return tfsWorkItem.Revision; }
    }

    public RevisionCollection Revisions
    {
      get { return tfsWorkItem.Revisions; }
    }

    public string State
    {
      get
      {
        return tfsWorkItem.State;
      }
      set
      {
        tfsWorkItem.State = value;
      }
    }

    public WorkItemStore Store
    {
      get { return tfsWorkItem.Store; }
    }

    public string Title
    {
      get
      {
        return tfsWorkItem.Title;
      }
      set
      {
        tfsWorkItem.Title = value;
      }
    }

    public WorkItemType Type
    {
      get { return tfsWorkItem.Type; }
    }

    public Uri Uri
    {
      get { return tfsWorkItem.Uri; }
    }

    public IWorkItem Copy()
    {
      return new WorkItemAdapter(tfsWorkItem.Copy());
    }

    public IWorkItem Copy(WorkItemType targetWIT)
    {
      return new WorkItemAdapter(tfsWorkItem.Copy(targetWIT));
    }

    public string GetNextState(string action)
    {
      return tfsWorkItem.GetNextState(action);
    }

    public bool IsValid()
    {
      return tfsWorkItem.IsValid();
    }

    public void Open()
    {
      tfsWorkItem.Open();
    }

    public void PartialOpen()
    {
      throw new NotImplementedException();
    }

    public void Reset()
    {
      tfsWorkItem.Reset();
    }

    public void Save()
    {
      tfsWorkItem.Save();
    }

    public void SyncToLatest()
    {
      tfsWorkItem.SyncToLatest();
    }

    public System.Collections.ArrayList Validate()
    {
      return tfsWorkItem.Validate();
    }

    #endregion
  }
}
